package com.yoomiito.app.widget.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.yoomiito.app.R;
import com.yoomiito.app.model.bean.AppInterfaceInfo;
import com.yoomiito.app.model.bean.OrderInfo;
import com.yoomiito.app.utils.AllUtils;
import com.yoomiito.app.utils.ImageLoader;
import com.yoomiito.app.utils.ResUtil;
import com.yoomiito.app.widget.wheelview.DateSelectDialog;

public class SelectDialog extends BaseDialog implements View.OnClickListener {

    private DateSelectDialog mDateDialog;
    private OnResultListener mOnResultListener;

    private String time = "";
    ImageView ivClose;
    TextView cancel;
    TextView sure;
    TextView tvTime;
    EditText tvName;

    public SelectDialog(@NonNull Context context) {
        this(context, 0);
    }

    public SelectDialog(@NonNull Context context, int themeResId) {
        super(context, R.style.dialog_2);
    }

    @Override
    public View setView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_select, null, false);
        cancel = view.findViewById(R.id.cancel);
        sure = view.findViewById(R.id.sure);
        sure.setOnClickListener(this);
        ivClose = view.findViewById(R.id.iv_close);
        ivClose.setOnClickListener(this);
        tvTime = view.findViewById(R.id.et_time);
        tvTime.setOnClickListener(this);
        tvName = view.findViewById(R.id.et_name);
        view.findViewById(R.id.cancel).setOnClickListener(this);
        setWidthPercent(1);
        setmGravity(Gravity.BOTTOM);
        return view;
    }

    @Override
    public void onBackPressed() {

    }

    private void selectDate() {
        if (mDateDialog == null) {
            mDateDialog = new DateSelectDialog(mContext);
            mDateDialog.setStartYear(1970)
                    .setmHeight(200)
                    .setListener(new DateSelectDialog.OnDateWheelViewListener() {
                        @Override
                        public void onResult(String date) {
                            time = date;
                            tvTime.setText(time);
                            tvTime.setTextColor(ContextCompat.getColor(mContext,R.color.color_balk_333333));
                            ivClose.setVisibility(View.VISIBLE);
                        }
                    });
        }
        mDateDialog.show();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sure:
                if (AllUtils.isFastClick()) {
                    return;
                }
                String name = tvName.getText().toString();
                if (mOnResultListener != null)
                    mOnResultListener.onResult(time, name);
                dismiss();
                break;
            case R.id.et_time:
                selectDate();
                break;
            case R.id.cancel:
                time = "";
                tvTime.setText("请选择登录时间");
                tvTime.setTextColor(ContextCompat.getColor(mContext,R.color.color_balk_999999));
                ivClose.setVisibility(View.GONE);
                tvName.setText("");
                if (mOnResultListener != null)
                    mOnResultListener.onResult("", "");
                dismiss();

                break;
            case R.id.iv_close:
                time = "";
                tvTime.setText("请选择登录时间");
                tvTime.setTextColor(ContextCompat.getColor(mContext,R.color.color_balk_999999));
                ivClose.setVisibility(View.GONE);
                break;

        }

    }


    public void setOnResultListener(OnResultListener onResultListener) {
        mOnResultListener = onResultListener;
    }


    public interface OnResultListener {
        void onResult(String time, String name);
    }


}
